-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload pending StateVersion #717
Upload pending StateVersion #717
Conversation
669a681
to
d0e9758
Compare
d0e9758
to
2b188a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes on minor stuff. Otherwise, looks 👍
state_version.go
Outdated
func (s *stateVersions) putURL(ctx context.Context, putURL string, data []byte) error { | ||
reader := bytes.NewReader(data) | ||
req, err := s.client.NewRequest("PUT", putURL, reader) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return req.Do(ctx, nil) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is duplicated in UploadTarGzip()
so I think this should belong as a Client
receiver method:
// or don't export this
func (c *Client) PutArchivistURL(ctx context.Context, archivistURL string, reader io.Reader) error {
req, err := c.NewRequest("PUT", archivistURL, reader)
// error handling omitted
return req.Do(ctx, nil)
}
It would eliminate the code duplication with UploadTarGzip()
in RegistryModules
, ConfigurationVersions
and Policies
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I don't think it should be exported but definitely shared.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This turned into an adventure! See my notes in the PR description under "Refactor Notes"
11da9a3
to
729c2de
Compare
I added response header hook support to IPRanges. Previously, it was not possible to encounter an HTTP status error on IPRanges because this condition could never be met: `if resp.StatusCode < 200 && resp.StatusCode >= 400 {`
729c2de
to
778c6d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this refactor, much cleaner than my original suggestion. 🚀
Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes. |
Description
Adds
pending
StateVersion support to the model as well as a new method Upload which creates and uploads and re-fetches a state version.Refactor Notes
This change alters the behavior of requests that are made directly to
IPRanges
endpoint and the object store forConfigurationVersions
,RegistryModels
,PolicySetVersions
, (and nowStateVersions
). Previously, we were reusing the normal request methods for these, which unnecessarily sent an Authorization header, and additionally attempted to use jsonapi decoding (with the exception ofIPRanges
, which seems to have fundamentally broken error handling)I added a new Client method,
doForeignPUTRequest
, which does an object-store-style application/octet-stream request with optional JSON response handling. The "foreign" part of the name reflects the fact that we aren't making API requests that have standard API features like Authorization with tokens and rate limiting.External links
Output from tests
Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.